package com.zlm.udp;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @Author: 郑
 * @Date: Create in 2020-3-16.
 */
public class UdpClientDemo2 {

    public static void main(String[] args) throws Exception {

        DatagramSocket socket = new DatagramSocket(9091);
        //准备数据，控制台获取
        boolean flag = true;
        while (flag) {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            String msg = bufferedReader.readLine();
            DatagramPacket dataPacket = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, InetAddress.getByName("localhost"), 9090);
            socket.send(dataPacket);
            if(msg.equals("bye")){
                flag = false;
            }
        }

        socket.close();
    }
}
